function [value isterminal direction] = eventfcn_limit(t,y,a)
global u



direction(1) = -1;
isterminal(1) = 0;
value(1) = 0;

pos = jpos_mat([0;0;y]);
if (pos(1,1) < pos(1,end))
    value(1) = h_sca(y);
    isterminal(1) = 1;
end


direction(2) = 1;
value(2) = 10-max(abs(y));
isterminal(2) = 1;

% direction(2) = 0;
% isterminal(2) = 1;
% value(2) = 3.4-max(abs(u));

% if t<0.01
% value(2) = 0;
% else
% % value(2) = 3.4-max(abs(u));
% value(2) = 3.4-max(u);
% end



end
